package server_list_dao

import (
	"go_server/login_server/initializer/mysql_init"
	"go_server/zinx/zlog"
	"go_server/zinx/zutils"
	"gorm.io/gorm"
)

type serverList struct {
	Address string `gorm:"column:address";json:"address"`
	Name string `gorm:"column:name";json:"name"`
	Status uint8 `gorm:"column:status";json:"status"`
	Id int `gorm:"column:id;primary";json:"id"`
	Recommend uint8 `gorm:"column:recommend";json:"recommend"`
	Used uint8 `gorm:"column:used";json:"used"`
}

func (serverList) TableName() string {
	return "server_list"
}

var (
	all_server_list_field = zutils.GetGormFields(serverList{})
)

func GetServerList() []*serverList {
	db := mysql_init.GetServerDBConnection()
	var list []*serverList
	if err := db.Select(all_server_list_field).Find(&list).Error; err != nil {
		if err != gorm.ErrRecordNotFound{
			zlog.Error("get server list failed!!!")
		}
		return nil
	}
	return list
}
